<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label">商品编号</label>
        <div class="layui-input-inline" style="width:500px">
            <input type="text" id="maeId" readonly="readonly" name="maeId" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-inline" style="width:500px">
            <input type="text" name="maename" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品规格</label>
        <div class="layui-input-inline" style="width:500px">
            <input type="text" name="model" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">材质</label>
        <div class="layui-input-inline" style="width:500px">
            <input type="text" name="texture" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">计件单位</label>
        <div class="layui-input-inline" style="width:500px">
            <input type="text" name="unit" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            $ = layui.$;
        var maeId = getQueryVariable("maeId");
        /*$("#prdId").val(prdId);*/
        //获取传递过来的参数
        function getQueryVariable(variable){
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }
        $.ajax({
            type:"post",
            data:{
                maeId:maeId,

            },
            url:"/material",
            error:function(XMLHttpRequest,textStatus,errorThrown){
                alert("执行失败了!");
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert("textStatus");

            },
            success:function(data){
                var mr = data.data;
                $("input[name='maeId']").val(mr.maeId);
                $("input[name='maename']").val(mr.maename);
                $("input[name='model']").val(mr.model);
                $("input[name='texture']").val(mr.texture);
                $("input[name='unit']").val(mr.unit);
                form.render();
            }

        })
        //监听新增订单提交按钮
        form.on('submit(saveBtn)', function (data) {
            // layer.alert(JSON.stringify(data))
            $.ajax({
                type:"post",
                url:"/updatematerial",
                data:{
                    maeId:data.field.maeId,
                    maename:data.field.maename,
                    model:data.field.model,
                    texture:data.field.texture,
                    unit:data.field.unit,
                },
                success:function(data){
                    var msg = data.msg;
                    layer.open({
                        title:['确认消息'],
                        content: msg,
                        btn: ['确定'],
                        shadeClose: true,
                        yes: function(index, layero){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            window.parent.location.reload();//刷新父页面
                            parent.layui.table.reload("data-table");
                        }
                    })
                }

            })

            return false;
        });

    });
</script>
</body>
</html>